﻿package rd.hardcore.engine 
{
	import adobe.utils.CustomActions;
	import flash.desktop.NativeApplication;
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import rd.hardcore.Datas;
	/**
	 * ...
	 * @author Thibault Perret
	 */
	public class SaveData
	{
		private const URL_PATH_XML	:	String = "file:///" + File.applicationDirectory.resolvePath("xml").nativePath+"\\trackS.xml";
		
		//private var fileName:String = "test.mp3";
		//private var name	:String = "test";
		
		public function SaveData(songNames : Array) 
		{
			trace(URL_PATH_XML);
			var file:File = new File(URL_PATH_XML);
			
			var child:XML;
			
			for each(var fileName:String in songNames) {
				var name:String = fileName.replace(".mp3", "");
				child = new XML("<track file=\"medias/sound/" + fileName + "\"><![CDATA[" + name + "]]></track>") ;
				Datas.datas.tracks.appendChild(child);
			}
			trace(Datas.datas);
			if(file.exists){
				var filestream:FileStream = new FileStream();
				filestream.open(file, FileMode.WRITE);
				// writeUTF place un symbole chelou devant le flush
				filestream.writeUTFBytes(Datas.datas);
				//filestream.writeUTF(Datas.datas.toXMLString());
				
			}else {
				trace("3: File doesn't exist");
			}
			
			
			
		}
		
	}

}